#include<iostream>
#include<unistd.h>
#include<cstdio>
#include<cstring>

using namespace std;

int main()
{   
    int fd[2];
    int ret = pipe(fd);

    pid_t pid=fork();
    if(pid<0)
    {
        perror("make fork");
        exit(-1);
    }

    if(pid==0) //child_precess
    {
        close(fd[0]);
        char buff[100];    //临时内存空间
        
        while(true)
        {
            cin.getline(buff,sizeof(buff));    //可以输出空格
            write(fd[1],buff,strlen(buff)+1);
        }   
    }
    else        //father_precess
    {
        close(fd[1]);
        char buff[100];
        while(true)
        {
            read(fd[0],buff,sizeof(buff));
            cout<<buff<<endl;
        }
    }
    return 0;
}
